#pragma once

#include <string>
#include "threadsafemap.h"
#include "libutilsbase.h"
#include "ustringutils.h"
#include "IQuoteAdapter.h"


class CThostFtdcMdApi;
class CMdHandler;


class CTPQUOTEAPI CCTPQuoteAdapter  : IQuoteService
{
public:
	CCTPQuoteAdapter(void);
	virtual ~CCTPQuoteAdapter(void);

public:
	virtual  bool Initialize(void* param);

	virtual bool InitializeByXML(const TCHAR* pcfg);

	virtual void UnInitialize();


	virtual bool SubscribeQuote_CTP( const TCHAR* Key,OnCTPQuoteRecieved callback );

	virtual void UnSubscribeQuote_CTP( const TCHAR* Key,OnCTPQuoteRecieved callback );

	

private:	

	bool WaitForReply();
public:
	bool ReqUserLogin();

	virtual bool GetLastError( std::pair<int,tstring>* perr );


	




private:
#pragma warning(disable : 4251)
	CTPQuoteParamA m_param;
	CThostFtdcMdApi* m_papi;
	CMdHandler* m_handler;
	friend class CMdHandler;

	theadmap<std::string ,OnCTPQuoteRecieved> m_maps;
	
};
